// pages/goumai/goumai.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address: {
      username:""
  },
    list:[],
    yue:"",
    ri:"",
    shi:"",
    fen:"",
    miao:"",
    zhou:"",
    pass: 123456,
    showPayPwdInput: false, //是否展示密码输入层
    pwdVal: '', //输入的密码
    payFocus: true, //文本框焦点
    blo:""
  },
  showInputLayer() {
    this.setData({
      showPayPwdInput: true,
      payFocus: true
    });
  },
  hidePayLayer() {
    this.setData({
      showPayPwdInput: false,
      payFocus: false
    });


  },
  /**
   * 获取焦点
   */
  getFocus() {
    this.setData({
      payFocus: true
    });
  },
  /**
   * 输入密码监听
   */
  inputPwd(e) {
    this.setData({
      pwdVal: e.detail.value
    });
    console.log(e);
    if (e.detail.value.length >= 6) {
        /**获取输入的密码**/
      var val = this.data.pwdVal;
    if (val != this.data.pass) {
      this.setData({
        showPayPwdInput: false,
        payFocus: false,
        pwdVal: '',
        blo:false
      }, function () {
        /**弹框**/
        wx.showToast({
          title: `${!this.data.blo?'密码错误':''}`
        })
      });
    } else if (val == this.data.pass) {
      this.setData({
        showPayPwdInput: false,
        payFocus: false,
        pwdVal: '',
        blo:true
      }, function () {
        /**弹框**/
       
        wx.showToast({
          title: `支付成功`,
        })
       
      });
      let shouhuo = wx.getStorageSync('shouhuo') || []
      let index = shouhuo.findIndex((v)=>v.goods_id==this.data.list.goods_id)
      if(index == -1){
        shouhuo.push(this.data.list) 
      }else{
        shouhuo.push(this.data.list) 
      }
      wx.setStorageSync('shouhuo', shouhuo.reverse())
                                                
      setTimeout(function(){
        wx.navigateTo({
          url: '/pages/shouhuo/shouhuo',
        })
      },1000)
    }
      this.hidePayLayer();
    }
  },
  jiesuan() {


    if(this.data.list.goods_price>0){
      this.showInputLayer();
    }
      
    

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //监听页面卸载

  
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {


    let time = new Date()
    let yue =time.getMonth()+1
    let ri = time.getDate()+1
    let shi =time.getHours()
    let fen = time.getMinutes()
    let miao = time.getSeconds()
    let zhou = time.getDay()+1
    console.log(`${yue}月${ri}日[周${zhou}]${shi}:${fen}`);
    let list = wx.getStorageSync('onelist')
    
    this.setData({
      list,
      yue,
      ri,
      shi,
      fen,
      miao,
      zhou
    })
    // let pages = getCurrentPages().length - 1;
    // console.log('需要销毁的页面：'+pages);
    // wx.navigateBack({
    //   delta: pages
    // })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})